package com.lhz.controller;

import com.lhz.manager.JobManager;
import com.lhz.model.entity.JobInfo;
import com.lhz.model.response.ResponseObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: LiHuaZhi
 * @Date: 2021/8/8 11:43
 * @Description:
 **/
@Tag(name = "内部调用")
@RestController
@RequestMapping("/distribute")
public class DistributeJobController {

    @Resource
    private JobManager jobManager;

    /**
     * 执行分配后的任务
     *
     * @param jobInfo
     * @return
     */
    @PostMapping("/start")
    public ResponseObject executorStartJob(@RequestBody JobInfo jobInfo) {
        jobManager.start(jobInfo);
        return ResponseObject.success();
    }

    /**
     * 暂停分配后的任务
     *
     * @param jobInfo
     * @return
     */
    @PostMapping("/stop")
    public ResponseObject executorStopJob(@RequestBody JobInfo jobInfo) {
        jobManager.stop(jobInfo);
        return ResponseObject.success();
    }

    @PostMapping("/health")
    public ResponseObject health() {
        return ResponseObject.success();
    }
}
